package com.think.in.spring.ioc.overview.dependency.injection;

import com.sun.media.sound.SoftTuning;
import com.think.in.spring.ioc.overview.repository.UserRepository;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.Environment;

/**
 * @author : zjj
 * @date : 2021/12/28 11:09
 */
public class DependencyInjectionDemo {

    public static void main(String[] args) {
        BeanFactory beanFactory = new ClassPathXmlApplicationContext("META-INF/dependency-injection-context.xml");
        // 自定义的Bean
        UserRepository userRepository =(UserRepository) beanFactory.getBean("userRepository");
        System.out.println(userRepository);
        // 自动注入的beanFactory 和我们自己去拿到的 beanFactory是否是一个东西
        // 容器内建的依赖
        System.out.println(userRepository.getBeanFactory());
        System.out.println(beanFactory);
        // 这里通过依赖注入 拿到 beanFactory
        System.out.println(userRepository.getBeanFactory() == beanFactory);
        // BeanFactory 是否是 Spring 中 的 Bean,这里是通过依赖查找 获取 beanFactory ,但是获取不到
   //     System.out.println(beanFactory.getBean(BeanFactory.class));

        System.out.println(userRepository.getObjectFactory().getObject());

        // 容器内建的Bean
        System.out.println(beanFactory.getBean(Environment.class));


        System.out.println(userRepository.getApplicationContextObjectFactory().getObject());




    }

    /**
     * BeanFactory :
     *
     * ApplicationContext :
     *
     *
     * @param userRepository
     * @param beanFactory
     */
    private static void whoIsIoCContainer(UserRepository userRepository,BeanFactory beanFactory){
        System.out.println(userRepository.getBeanFactory() == beanFactory);
    }
}
